package com.ceba.test.modules.email.service;
import java.util.List;

import com.ceba.base.helper.LoggerHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ceba.base.web.service.IBaseService;
import com.ceba.test.modules.email.dao.MsgEmailSetDao;
import com.ceba.test.modules.email.entity.MsgEmailSet;
import com.ceba.test.modules.email.entity.MsgMailSend;

import abc.data.DataRow;
import abc.data.DataTable;
import abc.data.store.IStore;
import abc.data.store.StoreManager;
import abc.object.XObject;

public class MsgEmailSetService extends IBaseService {

	private static Logger logger = LoggerFactory.getLogger(MsgEmailSetService.class);
	private MsgEmailSetDao msgEmailSetDao;

	
	
	/**
	 * 根据id获取
	 * @param Id
	 * @return
	 * @throws Exception
	 */
	public  DataTable getDataTableById(String Id) throws Exception{
		return msgEmailSetDao.getDataTableById(Id);

	}
	

	
	public  MsgEmailSet getMsgEmailSetById(String id){
		MsgEmailSet emailSet = new MsgEmailSet();
		emailSet.setId(id);
		try {
			DataTable dt = getDataTableById(id);
			if(dt !=null && dt.getRowCount()>0){
				DataRow dr = dt.getRow(0);
				emailSet.setId(dr.getString("ID"));
				emailSet.setEmailName(dr.getString("EMAIL_NAME"));
				emailSet.setTitle(dr.getString("TITLE"));
				emailSet.setContextTemplate(dr.getString("CONTEXT_TEMPLATE"));
				emailSet.setCallName(dr.getString("CALL_NAME"));
			}
		} catch (Exception e) {
			LoggerHelper.error(logger, e, "");
		}
		return emailSet;
	}
	
	
	
	/**
	 * 获取所有
	 * @return
	 * @throws Exception
	 */
	public  DataTable getDataTable(String type) throws Exception{
		return  msgEmailSetDao.getDataTableType(type);
	} 

	/**
	 * 修改
	 * @return
	 */
	public boolean modify(MsgEmailSet msgEmail){
		IStore store = StoreManager.create("msg_mail_set");
		XObject object = new XObject("ID",msgEmail.getId());
		object.put("TITLE", msgEmail.getTitle());
		object.put("EMAIL_NAME", msgEmail.getEmailName());
		object.put("CONTEXT_TEMPLATE", msgEmail.getContextTemplate());
		object.setUpdateUser();
		object.setUpdateTime();
		if(store.update(object)>0){
			return true;
		}
		return false;
	}
	

	
	
	/*
	 * 获取发送邮件列表
	 */
	 public List<MsgMailSend> getSendEMail() {
		return msgEmailSetDao.getSendEMail();
	}
	 
	 
	 
	 
	
	 
	 
	 
	 


	public MsgEmailSetDao getMsgEmailSetDao() {
		return msgEmailSetDao;
	}

	public void setMsgEmailSetDao(MsgEmailSetDao msgEmailSetDao) {
		this.msgEmailSetDao = msgEmailSetDao;
	} 

}
